package com.example.flutterappmydemo1

import android.util.Log
import android.widget.Toast
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
//import io.flutter.plugins.GeneratedPluginRegistrant

//java 版和 kotlin版不能共存，二者只能用其一，包名一相同就报错，注意清单文件包名的更换！！！
class MainActivity : FlutterActivity() {

    private val USERINFOEDITCHANNEL = "flutter_plugin_demo_kotlin"


    /*  override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          println("FlutterPluginDemoPlugin.onCreate 2")


          if (eventSink != null) {
              eventSink.success("原生层调用flutter方法123")
          } else {
              println("FlutterPluginDemoPlugin.onCreate eventSink is null")
          }
      }*/

  

    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        Log.i("tag", "configureFlutterEngine")
        //pushToUserInfoEditMethod
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, USERINFOEDITCHANNEL).setMethodCallHandler { call, result ->
            Log.i("tag", "configureFlutterEngine22222")

            when {
                call.method == "showToast" -> {
                    val text = call.argument<String>("text")
                    showToast(text + "1212");
                    result.success("success")
                }
                else -> result.notImplemented()
            }
        }


    }

    private fun showToast(text: String?) {
        println("MainActivity.showToastwss")
        Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
    }

   
}
